$(function () {
  //获取url的值
  let url = window.location.href;
  //截取 url中的“=”,获得“=”后面的参数
  let getcity = url.split("=");
  //解码url
  getcity = decodeURI(getcity[1]); //decodeURI解码


  //跳转主页
  $(".backIndex").click(function () {
    location.href = "./index.html?city="+getcity;
    // getcity='';
  });


  //根据城市渲染数据
  $.ajax({
    type:"get",
    timeout:5000,
    url:"http://api.tianapi.com/tianqi/index",
    data:{
        key:'60c783ccc05c6a72185d695b2aec2088',
        city:getcity
    },
    success:function(response){
        $(".details").each(function(index,item){
            $(item).html(`<div class="week">`+response.newslist[index].week+`</div>
            <div class="date">`+response.newslist[index].date+`</div>
            <div class="weather">`+response.newslist[index].weather+`</div>
            <div class="weatherPic"><img src="./image/img13.png" alt=""></div>
            <div class="lower">`+response.newslist[index].lowest+`</div>
            <div class="higher">`+response.newslist[index].highest+`</div>
            <div class="windsName">`+response.newslist[index].wind+`</div>
            <div class="windsIndex">`+response.newslist[index].windsc+`</div>`);
        })
    },
    error:function(e){
        alert(e);
    }
})
});
